package org.springblade.modules.admin.task;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import liquibase.pro.packaged.E;
import org.springblade.common.mq.MqMessageService;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.service.ElevatorService;
import org.springblade.modules.admin.service.IMaintainMalfunctionRescueService;
import org.springblade.modules.admin.service.IMaintainPlanConfigService;
import org.springblade.modules.admin.vo.MapUserInfoDetailVO;
import org.springblade.modules.admin.vo.RescueOrderDetail;
import org.springblade.modules.system.entity.Tenant;
import org.springblade.modules.system.service.ITenantService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Date 10:33 2023/10/9
 * @Description {
 * 电梯合同在保情况
 * }
 * @Author lsay
 **/
@Component
public class ElevatorMaintainStatusJob {

	@Resource
	private IMaintainMalfunctionRescueService maintainMalfunctionRescueService;
	@Resource
	private ElevatorService elevatorService;
	@Resource
	private ITenantService tenantService;
	@Resource
	private IMaintainPlanConfigService planConfigService;

	/**
	 * 定时任务：每日凌晨一点
	 */
	//@Scheduled(cron = "0 0 1 * * ?")
	@XxlJob(value = "updateElevatorMaintainStatus")
	public void updateElevatorMaintainStatus() {

		XxlJobHelper.handleSuccess("合同-更新有效电梯-方法(updateElevatorMaintainStatus)-[执行]开始");

		// 记录电梯合同在保情况
		try {
			elevatorService.updateElevatorMaintainStatusDay();
			XxlJobHelper.handleSuccess("合同-更新有效电梯-方法(updateElevatorMaintainStatus)-[执行]成功");
		} catch (Exception e) {
			XxlJobHelper.handleSuccess("合同-更新有效电梯-方法(updateElevatorMaintainStatus)-[执行]失败" + e);
		}

	}

	/**
	 * 定时任务：每日凌晨一点
	 */
	//@Scheduled(cron = "0 0 1 * * ?")
	@XxlJob(value = "updateElevatorScheduleLabel")
	public void updateElevatorScheduleLabel() {

		XxlJobHelper.handleSuccess("电梯排期-方法(updateElevatorScheduleLabel)-[执行]开始");

		// 记录电梯合同在保情况
		try {
			List<Tenant> tenantList = tenantService.list();
			if(Func.isNotEmpty(tenantList)){
				tenantList.forEach(e -> planConfigService.updateElevatorScheduleLabel(e.getTenantId()));
			}
			XxlJobHelper.handleSuccess("电梯排期-更新电梯排期标签-方法(updateElevatorScheduleLabel)-[执行]成功");
		} catch (Exception e) {
			XxlJobHelper.handleSuccess("电梯排期-更新电梯排期标签-方法(updateElevatorScheduleLabel)-[执行]失败" + e);
		}

	}
}
